package de.jmda.gen.java.impl;

import static de.jmda.core.mproc.ProcessingUtilities.getFields;
import static de.jmda.core.mproc.ProcessingUtilities.getTypeElement;
import static de.jmda.core.util.CollectionsUtil.asSet;
import static java.lang.System.lineSeparator;

import java.io.IOException;
import java.util.List;
import java.util.Set;

import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;

import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;

import de.jmda.core.mproc.task.AbstractTypeElementsTaskTypes;
import de.jmda.core.mproc.task.TaskException;
import de.jmda.core.mproc.task.TaskRunner;
import de.jmda.gen.GeneratorException;
import de.jmda.gen.java.InstanceFieldGenerator;

public class JUTDefaultInstanceFieldDeclarationGenerator
{
	private final static Logger LOGGER =
      Logger.getLogger(JUTDefaultInstanceFieldDeclarationGenerator.class);

	private class InstanceFieldContainer
	{
		@SuppressWarnings("unused")
    private List<String> strings;
	}
	
	private class Task extends AbstractTypeElementsTaskTypes
	{
		private TypeElement type;

		private Task(Set<? extends Class<?>> types)
		{
			super(types);
		}

		@Override
		public boolean execute() throws TaskException
		{
			type = getTypeElement(InstanceFieldContainer.class);
			return false;
		}
	}

	private InstanceFieldGenerator fieldDeclarationGenerator;

	@Before
	public void before() throws IOException
	{
		fieldDeclarationGenerator = new DefaultInstanceFieldGenerator();
	}
	
	@Test
	public void test() throws GeneratorException, IOException
	{
		Task task = new Task(asSet(InstanceFieldContainer.class));
		TaskRunner.run(task);
		
		for (VariableElement field : getFields(task.type))
		{
			fieldDeclarationGenerator.setTypeFrom(field);

			LOGGER.debug(
					field.toString() + lineSeparator() +
					fieldDeclarationGenerator.generate());

//			LOGGER.debug("field                            : " + field);
//			LOGGER.debug("field.asType                     : " + field.asType());
//
//			DeclaredType declaredType = asDeclaredType(field.asType());
//			
//			LOGGER.debug("field.asDeclaredType             : " + declaredType);
//			LOGGER.debug("field.asDeclaredTypeTypeElement  : " +
//					asTypeElement(declaredType).getQualifiedName());
//
////			LOGGER.debug("useType.asDeclaredTypeTypeElement: " +
////					getImportManager().useTypeOfField(field));
//
//			for (TypeMirror type : declaredType.getTypeArguments())
//			{
//				LOGGER.debug("type argument: " + type);
////				LOGGER.debug("useType.type: " + getImportManager().useType(type));
//			}
		}
	}
}